﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using System.Device.Location;

using SamuelBlanchard.Extenders;

namespace Techdays2013
{
    public partial class LaunchersPage : PhoneApplicationPage
    {
        #region Start
        public LaunchersPage()
        {
            InitializeComponent();
            this.Loaded += TextToSpeechPage_Loaded;
            this.BackKeyPress += TextToSpeechPage_BackKeyPress;
            this.GridFade.Visibility = System.Windows.Visibility.Visible;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        void TextToSpeechPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            this.GridFade.Visibility = System.Windows.Visibility.Visible;
            this.GridFade.FadeIn((s) => { NavigationService.GoBack(); });
        }

        /// <summary>
        /// On attent sue tout soit mise à jour
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        void TextToSpeechPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.GridFade.FadeOut((s) => { s.Visibility = Visibility.Collapsed; });
        }
#endregion

        #region SaveAppointmentTask

        private void SaveAppointmentTask_Click(object sender, RoutedEventArgs e)
        {
            SaveAppointmentTask saveAppointmentTask = new SaveAppointmentTask();

            DateTime startTime = new DateTime(2013, 2, 12, 14, 30, 0);
            saveAppointmentTask.StartTime = startTime;
            saveAppointmentTask.EndTime = startTime.AddHours(1);
            saveAppointmentTask.Subject = "Tirez parti des nouveautés de Windows Phone 8";
            saveAppointmentTask.Location = "Palais des Congrès de Paris";
            saveAppointmentTask.Details = "Windows Phone regorge d'APIs pour vous simplifier la vie et intégrer au mieux votre application dans le système. Si vous entendez que quelques lignes suffisent pour enregistrer un rendez-vous dans le calendrier de votre utilisateur, vous ne rêvez pas ! Nous ferons le tour des différents services à disposition pour créer facilement une belle expérience dans votre application : Géolocalisation, Cartographie, intégration dans les contacts, App to App, Speech, etc";
            saveAppointmentTask.IsAllDayEvent = false;
            saveAppointmentTask.Reminder = Reminder.FifteenMinutes;
            saveAppointmentTask.AppointmentStatus = Microsoft.Phone.UserData.AppointmentStatus.Busy;

            saveAppointmentTask.Show();
        }

        #endregion

        #region ShareMediaTask

        CameraCaptureTask cameraCaptureTask = new CameraCaptureTask();

        private void ShareMediaTask_Click(object sender, RoutedEventArgs e)
        {
            cameraCaptureTask.Completed += cameraCaptureTask_Completed;
            cameraCaptureTask.Show();
        }

        void cameraCaptureTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                ShowShareMediaTask(e.OriginalFileName);
            }
        }

        void ShowShareMediaTask(string path)
        {
            ShareMediaTask shareMediaTask = new ShareMediaTask();
            shareMediaTask.FilePath = path;
            shareMediaTask.Show();
        }

        #endregion

        #region MapsTask

        private void MapsTask_Click(object sender, RoutedEventArgs e)
        {
            MapsTask mapsTask = new MapsTask();

            //Center property to use the user's current location
            mapsTask.Center = new GeoCoordinate(48.878887, 2.283333); //Palais des Congrès

            mapsTask.SearchTerm = "Restaurant";
            mapsTask.ZoomLevel = 2;

            mapsTask.Show();
        }

        #endregion

        #region MapsDirectionTask

        private void MapsDirectionTask_Click(object sender, RoutedEventArgs e)
        {
            MapsDirectionsTask mapsDirectionsTask = new MapsDirectionsTask();

            // Palais des Congrès
            GeoCoordinate palaisCongresLocation = new GeoCoordinate(48.878887, 2.283333); 
            LabeledMapLocation palaisCongresLML = new LabeledMapLocation("Palais des Congrès", palaisCongresLocation);

            // Tour Eiffel
            GeoCoordinate tourEiffelLocation = new GeoCoordinate(48.8587, 2.2938);
            LabeledMapLocation tourEiffelML = new LabeledMapLocation("Tour Eiffel", tourEiffelLocation);

            mapsDirectionsTask.Start = palaisCongresLML;
            mapsDirectionsTask.End = tourEiffelML;

            mapsDirectionsTask.Show();
        }

        #endregion
    }
}